const log4 = require("log4js");
const path = require("path");
class Logger{
    async logger(ctx,next){
        try {
            log4.configure({
                appenders: {
                    info: {
                        type: "dateFile",
                        filename: path.join(__dirname, "../","../", "/log/interface"),
                        pattern: "yyyy-MM-dd.log",
                        encoding: "utf-8",
                        keepFileExt: true,
                        alwaysIncludePattern: true
                    }
                },
                categories: {
                    default: {
                        appenders: ['info'],
                        level: "info"
                    }
                }
            });
            const logger = log4.getLogger("info");
            logger.info("request=>" + JSON.stringify(ctx.request.body));
            await next();
            logger.info("response=>" + JSON.stringify(ctx.response));
        } catch (error) {
            console.log(error);
            await next()
        }
    }
}
module.exports = new Logger()